﻿namespace NMortgage.UI.ViewModels
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;

    using Caliburn.Micro;

    using NMortgage.UI.Events;
    using NMortgage.UI.Model;

    public sealed class FeeViewModel : Screen
    {
        #region Fields

        private readonly IEventAggregator eventAggregator;

        #endregion Fields

        #region Constructors

        public FeeViewModel(IEventAggregator eventAggregator)
            : this(eventAggregator, new Fee())
        {
        }

        public FeeViewModel(IEventAggregator eventAggregator, Fee fee)
        {
            this.eventAggregator = eventAggregator;
            Fee = fee;
        }

        #endregion Constructors

        #region Properties

        public Fee Fee
        {
            get;
            set;
        }

        public bool IsValid
        {
            get
            {
                IValidatable fee = this.Fee as IValidatable;
                return (fee != null) ? fee.IsValid : true;
            }
        }

        #endregion Properties

        #region Methods

        public void Cancel()
        {
            eventAggregator.Publish(new CancelEvent(this));
        }

        public void Finish()
        {
            if (IsValid)
            {
                eventAggregator.Publish(new ProfileItemAdded(Fee));
            }
        }

        #endregion Methods
    }
}